/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/

#pragma once

#include "MessageSubjectEnumerations.h"

#include <math.h>

namespace XF
{
	struct Message
	{
		int Subject;
		int SenderID;
		int ReceiverID;
		float SendTime;
		void* Data;
	};

	//these telegrams will be stored in a priority queue. Therefore the >
	//operator needs to be overloaded so that the PQ can sort the telegrams
	//by time priority. Note how the times must be smaller than
	//SmallestDelay apart before two Telegrams are considered unique.
	const double SmallestDelay = 0.25;


	inline bool operator==(const Message& m1, const Message& m2)
	{
		return ( fabs(m1.SendTime - m2.SendTime) < SmallestDelay) &&
			(m1.SenderID == m2.SenderID)        &&
			(m1.ReceiverID == m2.ReceiverID)    &&
			(m1.Subject == m2.Subject);
	}

	inline bool operator<(const Message& m1, const Message& m2)
	{
		if (m1 == m2)
		{
			return false;
		}

		else
		{
			return  (m1.SendTime < m2.SendTime);
		}
	}
}
